package com.heima.admin.controller.v1;

import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.SensitiveSelectDto;
import com.heima.admin.service.SensitiveService;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmSensitive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/sensitive")
public class SensitiveController {

    @Autowired
    private SensitiveService sensitiveService;

    @PostMapping("/list")
    private ResponseResult list(@RequestBody SensitiveSelectDto dto) {
        return sensitiveService.list(dto);
    }

    @PostMapping("/save")
    private ResponseResult save(@RequestBody WmSensitive sensitive) {
        boolean flag = sensitiveService.save(sensitive);
        if (flag) {
            return ResponseResult.okResult("添加成功");
        }else {
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "添加失败");
        }

    }

    @DeleteMapping("/del/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){
        boolean delete = sensitiveService.delete(id);
        if (delete) {
            return ResponseResult.okResult("删除成功");
        }else {
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "删除失败");
        }

    }

    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmSensitive sensitive) {
        boolean flag = sensitiveService.update(sensitive);

        if (flag) {
            return ResponseResult.okResult("修改成功");
        }else {
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "修改失败");
        }
    }


}
